

#include <sudoku.h>
#include <sdk_mem.h>

sudoku *sdk;

int main(int argc, char **argv){

  printf("sudosolve: version=%s\n", _SDK_VERSION);
  printf("  CPU name: %s\n", _SDK_PROC);
  printf("  CPU architecure: %s\n", _SDK_ARCH);
#ifdef _SDK_PROC_x86_64
  printf("  Using 64 bit: yes\n");
#else
  printf("  Using 64 bit: no\n");
#endif

  /* Build cpu flags string. */
  char cpu_flags[64]; // Have to be careful with this...
  memset(cpu_flags, 0, 64);
#ifdef _SDK_HAVE_MMX
  strcat(cpu_flags, "mmx ");
#endif
#ifdef _SDK_HAVE_SSE
  strcat(cpu_flags, "sse ");
#endif
#ifdef _SDK_HAVE_SSE2
  strcat(cpu_flags, "sse2 ");
#endif
#ifdef _SDK_HAVE_SSE3
  strcat(cpu_flags, "sse3 ");
#endif
#ifdef _SDK_HAVE_3DNow
  strcat(cpu_flags, "3DNow! ");
#endif

  printf("  Processor Flags: %s\n", cpu_flags);

#ifdef _DEBUG
  printf(" ** Compliled with debug on. **\n");
#endif
  if (argv[1] == NULL){
    printf("No sudoku file passed\n");
    printf("Usage: sudosolve <sudoku_file_path>\n");
    _sdk_die_msg("Exiting", 1);
  }
  //fprintf(stderr, "Start mem: %ld\n", _sdk_memory);
  printf("Loading sudoku from this file: %s\n", argv[1]);
  sdk = sdk_load_sudoku(argv[1]);
  if (!sdk){
    printf("Error loading this sudoku: %s\n", argv[1]);
    _sdk_die_msg("Exiting", 1);
  }
  //fprintf(stderr, "End mem: %ld\n", _sdk_memory);

  sudoku *solved = _sdk_rec_solve(sdk);

  _sdk_print_sdk_vals(solved);

  fprintf(stderr, "Total memory usage: %ld\n", _sdk_memory);

  return 0;

}
